<template>
    <div>
      <!-- 订单管理 -->
      <!-- 面包屑 -->
        <el-breadcrumb separator-class="el-icon-arrow-right">
          <el-breadcrumb-item :to="{ path: '/welcome' }">首页</el-breadcrumb-item>
          <el-breadcrumb-item>订单管理</el-breadcrumb-item>
          <el-breadcrumb-item>订单列表</el-breadcrumb-item>
        </el-breadcrumb>
        <!-- 内容区 -->
        <el-card style='margin-top:20px'>
          <!-- 搜索订单 -->
          <el-input placeholder="请输入订单编号" v-model="orederName" class="input-with-select">
            <el-button slot="append" icon="el-icon-search" @click="Search"></el-button>
          </el-input>
          <!-- 列表 -->
          <el-table
            :data="orderData"
            border
            style="width: 100%">
            <el-table-column type="index" label="#" width="80"></el-table-column>
            <el-table-column prop="order_number" label="订单编号" width="180"></el-table-column>
            <el-table-column prop="order_price" label="订单价格" ></el-table-column>
            <el-table-column prop="order_pay" label="是否付款" >
              <template slot-scope="scope">
                <el-tag type="warning" v-if="scope.row.order_pay === '0'">未付款</el-tag>
                <el-tag type="success" v-else>已付款</el-tag>
              </template>
            </el-table-column>
            <el-table-column prop="is_send" label="是否发货" ></el-table-column>
            <el-table-column prop="create_time" label="下单时间" >
              <template slot-scope="scope">
                <span>{{scope.row.create_time | dateFormat}}</span>
              </template>
            </el-table-column>
            <el-table-column label="操作" >
              <template slot-scope="scope">
                <el-tooltip class="item" effect="dark" content="修改地址信息" placement="top">
                <el-button type="primary" icon="el-icon-edit" size="small" @click="modaddress"></el-button>
                </el-tooltip>
                <el-tooltip class="item" effect="dark" content="物流进度" placement="top">
                <el-button type="success" icon="el-icon-location-outline" size="small" @click="openLogistics(scope.row)"></el-button>
                </el-tooltip>
              </template>
            </el-table-column>
          </el-table>
          <!-- 分页功能 -->
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :page-sizes="[5, 10, 20, 40]"
            :page-size="5"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
          </el-pagination>
          <!-- 修改地址信息弹窗 -->
          <el-dialog
            title="修改地址信息"
            :visible.sync="addressVis"
            width="30%">
            <el-form :model="addressFrom"  :rules="addressRules" ref="addressRef" label-width="100px" class="demo-ruleForm">
              <el-form-item label="省市区县">
              <el-cascader
                :options="cityOptions"
                v-model="addressFrom.city"
                @change="changeProvince"
                change-on-select
              >
              </el-cascader>
              </el-form-item>
              <el-form-item label="详细地址" prop="about">
                <el-input v-model="addressFrom.about"></el-input>
              </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
              <el-button @click="addressVis = false">取 消</el-button>
              <el-button type="primary" @click="suremodadd">确 定</el-button>
            </span>
          </el-dialog>
          <!-- 打开物流信息-->
          <el-dialog
            title="物流信息"
            :visible.sync="LogisticsVis"
            width="50%">
            <el-timeline :reverse="reverse">
              <el-timeline-item
                v-for="(item, index) in LogisticsData"
                :key="index"
                :timestamp="item.context">
                {{item.ftime}}
              </el-timeline-item>
            </el-timeline>
            <span slot="footer" class="dialog-footer">
              <el-button @click="LogisticsVis = false">取 消</el-button>
              <el-button type="primary" @click="LogisticsVis = false">确 定</el-button>
            </span>
          </el-dialog>

        </el-card>
    </div>
</template>

<script>
import cityOptions from '@/plugins/city_data2017_element.js'
export default {
    data() {
        return {
          orederName:"",
          orderData:[],
          queryInof:{
            query:'',
            pagenum:1,
            pagesize:5
          },
          total:0,
          addressVis:false,
          LogisticsVis:false,
          cityOptions: cityOptions,
          addressFrom:{
            city:'',
          },
          addressRules:{
            
            about:[
              { required: true, message: '请输入详细地址', trigger: 'blur' }
            ]
          },
          LogisticsData:[],
          reverse: true,
        };
    },
    created() {
      this.goorderData()
    },
    mounted() {

    },
    methods: {
      async goorderData(){
        const {data:res} =await this.$http.get('orders',{params:this.queryInof})
        console.log(res);
        if(res.meta.status ==! 200) return this.$message.error('获取订单列表失败')
        this.orderData = res.data.goods
        this.total =res.data.total
      },
      handleSizeChange(val) {
        this.queryInof.pagesize =val
      },
      handleCurrentChange(val) {
        this.queryInof.pagenum =val
      },
      //点击搜索
      Search(){
        this.queryInof.query = this.orederName
        this.goorderData()
      },
      //打开修改地址
      modaddress(){
        this.addressVis =true
      },
      changeProvince(){
        console.log(this.addressFrom.city);
        
      },
      //确定修改
      suremodadd(){
        this.$refs.addressRef.validate(vaild => {
          if(!vaild || this.addressFrom.city.length <2) return this.$message.error('请完善信息')
          this.addressVis =false
        })},
      //打开物流信息
      async openLogistics(row){
        this.LogisticsVis =true
        console.log(row.order_id);
        const {data:res} = await this.$http.get(`/kuaidi/1106975712662`)
        console.log(res);
      }
    }
};
</script>

<style scoped>
.el-table{
  margin-top: 20px;
}
.el-pagination{
  margin-top: 20px;
}

</style>
